package com.iqiyi.service.impl;

import com.iqiyi.dto.*;
import com.iqiyi.mapper.SearchMapper;
import com.iqiyi.po.Sort;
import com.iqiyi.po.Video;
import com.iqiyi.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
@Service
public class SearchServiceImpl implements SearchService {
    @Autowired
    private SearchMapper searchMapper;
    @Override
    public List findVideo(String name) {
//        ArrayList arrayList1 = new ArrayList();
//        ArrayList arrayList2 = new ArrayList();
        ArrayList arrayList3 = new ArrayList();
        List<VideoList> videoList = searchMapper.findVideoList(name);
//        if (videoList!=null || videoList.size()>0){
//            for (VideoList videoName:videoList) {
//                List<VideoName> vName = searchMapper.findVideoName(videoName.getVname());
//                List<JuJiNumber> nums = searchMapper.findNums(videoName.getVname());
//                arrayList1.add(vName);
//                arrayList2.add(nums);
//            }
//        }

        if (videoList.size()>0){
            List<VideoName> videoName = searchMapper.findVideoName(videoList.get(0).getVname());
            List<JuJiNumber> nums = searchMapper.findNums(videoList.get(0).getVname());
            arrayList3.add(videoList);
            arrayList3.add(videoName);
            arrayList3.add(nums);
            return arrayList3;
        }
        return videoList;
    }

    @Override
    public List findActor(String name) {
        List<ActorList> actorList = searchMapper.findActorList(name);
        ArrayList arrayList = new ArrayList();
        if (actorList.size()>0){
            List<ActorPic> actorPic = searchMapper.findActorPic(actorList.get(0).getAname());
            arrayList.add(actorList);
            arrayList.add(actorPic);
            return arrayList;
        }
        return actorList;
    }
    @Override
    public List<VideoList> findAllVideo(String vname) {
        return  searchMapper.findVideoList(vname);
    }

    @Override
    public Boolean updateVideo(VideoList videoList) {
        int i = searchMapper.updateVideo(videoList);
        if(i>0){
            Sort sort = searchMapper.findSort(videoList.getSname());
            int i1 = searchMapper.updateVideoAndSort(videoList.getVid(), sort.getSid());
            if(i1>0){
                return true;
            }
            return null;
        }
        return null;
    }
}
